package com.ruoyi.ax.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.ax.domain.AxOrder;
import com.ruoyi.ax.service.IAxOrderService;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ax.domain.AxAuthorizationSell;
import com.ruoyi.ax.service.IAxAuthorizationSellService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 委拍记录Controller
 * 
 * @author ruoyi
 * @date 2025-05-07
 */
@RestController
@RequestMapping("/ax/axAuthorizationSell")
public class AxAuthorizationSellController extends BaseController
{
    @Autowired
    private IAxAuthorizationSellService axAuthorizationSellService;
    @Autowired
    private IAxOrderService axOrderService;

    /**
     * 查询委拍记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AxAuthorizationSell axAuthorizationSell)
    {
        startPage();
        List<AxAuthorizationSell> list = axAuthorizationSellService.selectAxAuthorizationSellWithOrderList(axAuthorizationSell);
        return getDataTable(list);
    }


    /**
     * 我的委拍
     */
    @GetMapping("/mylist")
    @Log(title = "我的委拍", businessType = BusinessType.EXPORT)
    public TableDataInfo mylist(AxOrder axOrder)
    {
        startPage();
        axOrder.setOrderType(1l);
        if(StringUtils.isEmpty(axOrder.getPlatform())){
            axOrder.setPlatform("A");
        }
        axOrder.setSysUserId(SecurityUtils.getUserId());
        List<AxOrder> list = axOrderService.selectAxOrderList(axOrder);
        return getDataTable(list);
    }
    /**
     * 我的委拍记录
     */
    @GetMapping("/mylistRecord")
    @Log(title = "我的委拍记录", businessType = BusinessType.EXPORT)
    public TableDataInfo mylistRecord(AxAuthorizationSell axAuthorizationSell)
    {
        startPage();
        axAuthorizationSell.setSysUserId(SecurityUtils.getUserId());
        List<AxAuthorizationSell> list = axAuthorizationSellService.selectAxAuthorizationSellWithOrderList(axAuthorizationSell);
        return getDataTable(list);
    }



    /**
     * 导出委拍记录列表
     */
    @Log(title = "委拍记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AxAuthorizationSell axAuthorizationSell)
    {
        List<AxAuthorizationSell> list = axAuthorizationSellService.selectAxAuthorizationSellWithOrderList(axAuthorizationSell);

        for(AxAuthorizationSell axAuthorizationSell1:list){
            SysUser sysUser = axAuthorizationSell1.getSysUser();
            BeanUtils.copyProperties(sysUser,axAuthorizationSell1);
           // axOrder1.setRoundName(axOrder1.getAxGood().getAxRound().getRoundName());
            axAuthorizationSell1.setGoodName(axAuthorizationSell1.getAxGood().getGoodName());
            //  axOrder1.setGoodImg(axOrder1.getAxGood().getGoodImg());
        }

        ExcelUtil<AxAuthorizationSell> util = new ExcelUtil<AxAuthorizationSell>(AxAuthorizationSell.class);
        util.exportExcel(response, list, "委拍记录数据");
    }

    /**
     * 获取委拍记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(axAuthorizationSellService.selectAxAuthorizationSellById(id));
    }

    /**
     * 新增委拍记录
     */
    @Log(title = "委拍记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AxAuthorizationSell axAuthorizationSell)
    {
        return toAjax(axAuthorizationSellService.insertAxAuthorizationSell(axAuthorizationSell));
    }

    /**
     * 修改委拍记录
     */
    @Log(title = "委拍记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AxAuthorizationSell axAuthorizationSell)
    {
        return toAjax(axAuthorizationSellService.updateAxAuthorizationSell(axAuthorizationSell));
    }

    /**
     * 删除委拍记录
     */
    @Log(title = "委拍记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(axAuthorizationSellService.deleteAxAuthorizationSellByIds(ids));
    }
}
